<template>
  <el-dialog :title="registerData.title" :visible.sync="registerData.show" width="600px">
    <el-form :model="parames" :rules="rules" label-width="130px" ref="parames">
      <el-form-item label="操作:" prop="type">
        <el-switch
          v-model="parames.type"
          active-value="1"
          inactive-value="0"
          active-text="增加"
          inactive-text="减少"
        ></el-switch>
      </el-form-item>
      <el-form-item label="增加条数:" prop="num">
        <el-input v-model="parames.num" type="number" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="registerData.show = false">取 消</el-button>
      <el-button type="primary" @click="handleSend">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      parames: {
        num: "",
        type: "1"
      },
      rules: {
        num: [{ required: true, message: "请输入次数", trigger: "blur" }]
      }
    };
  },
  props: ["registerData"],
  methods: {
    handleClose() {
      this.registerData.show = false;
    },
    resetData() {
    this.parames.num = ''
      this.$refs.parames.resetFields();
    },
    handleSend() {
      this.$refs.parames.validate(valid => {
        if (valid) {
          this.$axios
            .post("/tx/report/modify_regnum", {
              type: this.parames.type,
              urlId: this.registerData.urlId,
              statDate: this.registerData.statDate,
              num: this.parames.num
            })
            .then(res => {
              if (res.code === 10200) {
                this.$emit('render')
                this.$message({
                  message: "操作成功！",
                  type: "success"
                });
                setTimeout(() => {
                  this.handleClose();
                }, 200);
              }
            });
        }
      });
    }
  },
  computed: {
    changeDialog() {
      return this.registerData.show;
    }
  },
  watch: {
    changeDialog(culval) {
      if (culval) {
      } else {
        this.resetData();
      }
    }
  }
};
</script>
<style>
</style>
